Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.request = exports.interfaceAddress = void 0;
var e = require("../../@babel/runtime/helpers/toArray"),
  t = require("../../@babel/runtime/helpers/regeneratorRuntime"),
  r = require("../../@babel/runtime/helpers/asyncToGenerator"),
  n = require("../../@babel/runtime/helpers/objectSpread2"),
  o = require("../../store/index"),
  config = require('../../config/index'),
  a = {
    DEV: "http://8.130.111.125:10007",
    PRE: "http://relase.jxapi.kkbbi.com",
    PRO: "https://api.zhaogongdi.com"
  };
exports.interfaceAddress = a;

function getToken(requestData) {
  return new Promise((resolve, reject) => {
    wx.login({
      success: (res) => {
        var code = res.code
        wx.request({
          url: config.REQUEST_JAVA_LIST.DEV + '/auth/login',
          method: "POST",
          data: {
            code
          },
          success(res) {
            var response = res.data
            wx.setStorageSync('token', response.data)
            $.request[requestData.method.toUpperCase() + requestData.url](
              requestData.data
            ).then(res => {
              res = res[0]
              resolve(res)
            })
          },
          fail(error) {
            reject()
          }
        })
      },
    })
  })


}
var s = function (e) {
    var t, r = (0, o.getState)().storage;
    return n({
      "content-type": "application/json",
      "Authorization": wx.getStorageSync('token') || ""
    }, e.headers)
  },
  u = function (e, t, r, requestData) {
    var n = e.statusCode,
      a = e.data,
      pages, path;
    if (n) {
      if (a.code == 11000) {
        $.showModal({
          title: "账号异常",
          content: a.msg
        }).then((function () {
          wx.makePhoneCall({
            phoneNumber: '18679426460'
          })
        }))
      } else if (a.code == 11009) {
        getToken(requestData).then((res) => {
          t([res]);
          r(res.data)
        })
      } else if (a.code === 11010) {
        $.router.push("/subpackage/login/auth/index")
      } else {
        t([a])
        r(e)
      }
    }
    
  };
var i = new Proxy({}, {
  get: function (n, o) {

    return function (n, i) {

      var c = o.split("/"),
        l = e(c),
        d = l[0],
        p = l.slice(1);

      return function (e) {
        return new Promise((function (n, o) {
          var requestData = e;
          wx.request({
            url: config.REQUEST_JAVA_LIST.DEV + e.url,
            data: (null == e ? void 0 : e.data) || null,
            method: e.method,
            dataType: "json",
            header: s(e),
            success: function (e) {
              u(e, n, o, requestData);
            },
            fail: function (error) {
              console.log(error)
              o([null])
            }
          })
        }))
      }({
        method: d.toLowerCase(),
        url: "/".concat(p.join("/")),
        data: n,
        headers: i
      })
    }
  }
});
exports.request = i;